package cn.hp.cms.servlet.user;

import cn.hp.cms.service.UserService;
import cn.hp.cms.service.impl.UserServiceImpl;
import cn.hp.cms.utils.Constant;
import cn.hp.cms.utils.JsonForServlet;
import cn.hp.cms.utils.ResultData;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/userLogin.do")
public class LoginServlet extends HttpServlet {
//    使用service层
    private UserService userService = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        用户登录代码
        String userName = req.getParameter("userName");
        String password = req.getParameter("password");
        String checkCode = req.getParameter("checkCode");
        ResultData resdata = userService.login(userName, password , checkCode ,req);
        JsonForServlet.writeData(resp,resdata);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
